const filesize = (filesize) => {
    if(filesize > 1024 * 1024 * 1024) {
        return (filesize / 1024 / 1024 / 1024).toFixed(2) + 'GB'
    } else if(filesize > 1024 * 1024) {
        return (filesize / 1024 / 1024).toFixed(2) + 'MB'
    } else {
        return (filesize / 1024).toFixed(2) + 'KB'
    }
}

const sponsorType = function(type){
    return ['主办方', '承办方', '赞助商'][type - 1]
}
const getTime = function (datetime) {  
    datetime = datetime || ''
    return datetime.split(' ')[1]  
}
const getDate = function (datetime) {  
    datetime = datetime || ''
    return datetime.split(' ')[0]  
}

const fileIcon = function(filename){ 
    let type = 2, postfix, maps;
    postfix = filename.substring(
        filename.lastIndexOf(".") + 1,
        filename.length
    );
    postfix = postfix.toLowerCase()
    maps = {
        'ppt|pptx': 0,
        'doc|docx|xls|xlsx': 1,
        'png|gif|jpeg|jpg|bmp|': 2,
    }
    for(let key in maps) {
        if(key.indexOf(postfix) !== -1) {
            type =  maps[key]
            break;
        }
    }
    let basePath = '//lres.gzhc365.com/med/mobile/dist/'
    let icons = [
        'ppt_icon.png',
        'word_icon.png',
        'png_icon.png', 
        'pdf_icon.png',
        'zip_icon.png'
    ];
    return basePath + (icons[type] || 'png_icon.png')
}

const currency = function(price) {
    if(isNaN(price)) return '';
    return price.toFixed(2);
}
const gender = (type)=>{
    const types = ['未知', '男', '女']
    return types[type]
}

const inviteStatus = (type)=>{
    const types = ['待处理', '已同意', '已拒绝', '已失效']
    return types[type]
}

export {
    filesize,
    sponsorType,
    getTime,
    getDate,
    fileIcon,
    currency,
    gender,
    inviteStatus
}